package com.junzhiit.nengji.cms.web.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.cms.service.QuestionTypeService;
import com.junzhiit.nengji.cms.web.vo.DataTablesParamVO;
import com.junzhiit.nengji.cms.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/question/type")
public class QuestionTypeController extends BaseController {

	@Autowired
	private QuestionTypeService questionTypeService;

	@ApiOperation(value = "获取所有问题类型列表")
	@RequestMapping(method = RequestMethod.GET)
	public Map<String, Object> findAll(DataTablesParamVO dtp, String name) {
		return questionTypeService.findAll(dtp, name);
	}

	@ApiOperation(value = "根据ID查询问题类型")
	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	public ResultVO findById(@PathVariable String id) {
		AssertUtil.notBlank(id, "id is required.");
		return questionTypeService.findById(id);
	}

	@ApiOperation(value = "创建问题类型")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(String name) {
		AssertUtil.notBlank(name, "name is required.");
		return questionTypeService.add(name);
	}

	@ApiOperation(value = "修改问题类型")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO update(String id,String name) {
		AssertUtil.notBlank(id, "id is required.");
		AssertUtil.notBlank(name, "name is required.");
		return questionTypeService.edit(id,name);
	}

	@ApiOperation(value = "删除问题类型")
	@RequestMapping(value = "/del", method = RequestMethod.PUT)
	public ResultVO delete(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return questionTypeService.delete(id);
	}

	@ApiOperation(value = "查询问题分类下拉框")
	@RequestMapping(value = "/list", method = RequestMethod.GET)
	public ResultVO getList() {
		return questionTypeService.getList();
	}
	
	@ApiOperation(value = "置顶")
	@RequestMapping(value = "/toTop", method = RequestMethod.PUT)
	public ResultVO toTop(String id) {
		AssertUtil.notBlank(id, "id is required.");
		return questionTypeService.toTop(id);
	}
}
